#include <plugins_manager_appfwk/qls_vtabbar.h>

#include <QStyleOptionTab>
#include <QStylePainter>

QSize QLsVTabBar::tabSizeHint(int index) const
{
    QSize s = QTabBar::tabSizeHint(index);
    s.transpose();
    s += QSize(s.height() / 2,
               0); /* 2. 缩小了内容的rect后，文字显示不全：放大标签条的rect */
    return s;
}

void QLsVTabBar::paintEvent(QPaintEvent *)
{
    QStylePainter painter(this);
    QStyleOptionTab opt;

    for (int i = 0; i < count(); i++) {
        initStyleOption(&opt, i);
        painter.drawControl(QStyle::CE_TabBarTabShape, opt);
        painter.save();

        QSize s = opt.rect.size();
        s.transpose();
        s += QSize(
            0, -s.width() /
                   2); /* 1. 加了图标之后，图标超出左侧边界：缩小内容的rect */
        QRect r(QPoint(), s);
        r.moveCenter(opt.rect.center());
        opt.rect = r;

        QPoint c = tabRect(i).center();
        painter.translate(c);
        painter.rotate(90);
        painter.translate(-c);
        painter.drawControl(QStyle::CE_TabBarTabLabel, opt);
        painter.restore();
    }
}
